<template>
	<div class="page">
		<div class="logo">
			<img class="logo-img" src="../assets/userLogo-2.png" alt="" />
			<div class="right-ic" @click="changeLanguage">
				<img src="../assets/100-1.png" alt="" />
				<span>{{$i18n.locale == 'zh' ? 'EN' : '中文'}}</span>
			</div>
		</div>
		<div class="content">
			<div class="search-wrap">
				<div class="search">
					<input type="text" v-model="search" :placeholder="$t('language.search1')" />
					<img class="ic" src="../assets/101.png" alt="" />
				</div>
				<div class="tab-wrap">
					<div class="tab" :class="{'select': select == 2}" @click="tapNav(2)">{{$t('language.text42')}}</div>
					<div class="tab" :class="{'select': select == 1}" @click="tapNav(1)">{{$t('language.text43')}}</div>
				</div>
			</div>
		
			<van-list v-model="loading" :finished="finished" :finished-text="$t('language.noMore')" @load="onLoad">
				<div class="card" v-for="item in list" :key="item.id">
					<div class="user">
						<div class="user-left">
							<div class="user-name">
								{{$i18n.locale == 'zh' ? item.english_name : item.name}}
								<span class="tag">{{item.position}}</span>
							</div>
							<div class="user-text">{{$i18n.locale == 'zh' ? item.hotel.title : item.hotel.title_en}}</div>
							
						</div>
						<div class="user-img">
							<img :src="item.avatar" alt="" />
						</div>
					</div>
					<div class="info-wrap">
						<div class="info">{{$t('language.text28')}}：<span class="num">{{item.lnr_count}}</span></div>
						<div class="info">{{ $i18n.locale == "zh" ? `${computeDate(item.created_at) + $t("language.text15") }` : `${ $t("language.text15") + computeDate(item.created_at)}` }}: <span class="num">{{item.lnr_room_count}}</span></div>
						<div class="btn" v-if="select !== 2" @click="goPage('assignStaff', item.id)">
							<span>{{$t('language.text35')}}</span>
							<img src="../assets/111.png" alt="" />
						</div>
					</div>
					<div class="tap-lnr" @click="goMySell('mySell', item)">
						<span>{{$t('language.text30')}}</span>
						<van-icon name="arrow" />
					</div>
				</div>
			</van-list>
		</div>

		<div class="add-btn">
			<div class="btn" @click="goPage('customer')">
				<img src="../assets/tab-2.png" alt="" />
				<span>{{$t('language.text34')}}</span>
			</div>
			<div class="btn" @click="goPage('sell')">
				<img src="../assets/tab-1.png" alt="" />
				<span>{{$t('language.text33')}}</span>
			</div>
			<!-- <div class="btn select">
				<img src="../assets/tab-selcet-3.png" alt="" />
				<span>{{$t('language.text35')}}</span>
			</div> -->
			<div class="btn" @click="goPage('check')">
				<img src="../assets/tab-4.png" alt="" />
				<span>{{$t('language.text36')}}</span>
			</div>
			<div class="btn"  @click="goPage('forms')">
				<img src="../assets/tab-5.png" alt="" />
				<span>{{$t('language.text37')}}</span>
			</div>
		</div>

	</div>
</template>
<script>
	import {
		getUserLists
	} from '@/api/user';
	let timer = null

	export default {
		name: 'Sell',
		data: function() {
			return {
				locale: 'zh',
				search: '',
				list: [],
				loading: false,
				finished: false,
				page: 1,
				select: 2
			};
		},
		created() {},
		mounted() {},
		watch: {
			search: function() {
				const t = this
				if (timer != null) clearTimeout(timer)
				
				timer = setTimeout(() => {
					timer = null
					clearTimeout(timer)
					t.page = 1
					t.list = []
					t.getUserListsData()
				}, 500)
			}
		},
		methods: {
			computeDate(str) {
				let date = new Date(str);
				date.setMonth(date.getMonth() - 1);
				return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}`;
			},
			tapNav(item) {
				this.select = item
				this.page = 1
				this.list = []
				this.getUserListsData()
			},
			onLoad() {
				this.getUserListsData()
			},
			getUserListsData() {
				getUserLists({
					page: this.page,
					key: this.search,
					leave: this.select
				}).then((res) => {
					let { current_page, last_page, data } = res.data
					// 加载状态结束
					this.loading = false;
					// 数据全部加载完成
					if (current_page == last_page) {
						this.finished = true;
					} else {
						this.finished = false;
						this.page ++
					}
					this.list = [...this.list, ...data]
				}).catch((err) => {
					this.loading = false;
					console.log(err)
				})
			},
			goMySell(page, item) {
				const data = {
					id: item.id,
					name: item.name,
					english_name: item.english_name,
					avatar: item.avatar,
					title: item.hotel.title,
					title_en: item.hotel.title_en,
					position: item.position,
				}
				this.$router.push({
					path: page,
					query: data
				})
			},
			goPage(page, id) {
				this.$router.push({
					path: page,
					query: {
						id
					}
				})
			},
			changeLanguage() {
				if (this.$i18n.locale == 'zh') {
					this.$i18n.locale = 'en';
					this.$cookies.set('locale', 'en')
				} else {
					this.$i18n.locale = 'zh';
					this.$cookies.set('locale', 'zh')
				}
			}
		}
	};
</script>
<style type="text/css" lang="scss" scoped>
	.page {
		background-color: #f2f5f7;
	}

	.logo {
		background-color: #fff;

		.tab-app {
			display: flex;
			align-items: center;
			font-size: 24px;
			color: #333333;
			
			img {
				width: 31px;
				height: 30px;
				margin-right: 6px;
			}
		}

		.right-ic {
			color: #333333;
		}
	}

	.content {
		padding-bottom: 80px;

		.search-wrap {
			padding: 40px 30px 0 30px;
			background-color: #fff;

			.search {
				position: relative;
				z-index: 10;
				padding: 0 28px;
				height: 74px;
				border: 2px solid #1f4456;
				background-color: #fff;
				box-sizing: border-box;
				border-radius: 45px;
				display: flex;
				align-items: center;
				justify-content: space-between;

				input {
					font-size: 24px;
					color: #666;
					width: 100%;
					height: 100%;
				}

				.ic {
					width: 28px;
					height: 28px;
					flex-shrink: 0;
				}
			}
			
			.tab-wrap {
				display: flex;
				justify-content: space-around;
				align-items: center;
				.tab {
					padding: 32px 0 24px;
					font-size: 30px;
					font-weight: bold;
					color: #565B64;
					line-height: 60px;
					&.select {
						color: #1F4456;
						position: relative;
						&::after {
							content: '';
							position: absolute;
							left: 50%;
							bottom: 0;
							transform: translateX(-50%);
							width: 100%;
							height: 4px;
							background-color: #E8542C;
						}
					}
				}
			}
		}

		.card {
			margin: 24px 30px 0;
			padding: 30px;
			box-sizing: border-box;
			border-radius: 10px;
			background-color: #fff;
			box-shadow: 0 0 24px #eee;
			position: relative;

			.user {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				box-sizing: border-box;

				.user-left {
					color: #333333;

					.user-name {
						font-size: 36px;
						font-weight: bold;
						.tag {
							position: relative;
							top: 4px;
							color: #E8542C;
							margin-left: 12px;
							display: inline-block;
							max-width: 300px;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							padding: 8px 12px;
							border-radius: 18px 18px 18px 0;
							font-size: 20px;
							background-color: #FBE8E2;
							
						}
					}
					.user-text {
						font-size: 24px;
					}
				}

				.user-img {
					width: 120px;
					height: 120px;
					flex-shrink: 0;
					margin-left: 24px;
					border-radius: 50%;
					border: 1px solid #fff;
					overflow: hidden;

					img {
						width: 100%;
						height: 100%;
					}
				}
			}

			.title {
				font-size: 30px;
				color: #333333;
				padding-bottom: 10px;
				font-weight: bold;
			}

			.info-wrap {
				margin-top: 40px;
				position: relative;
				
				.info {
					font-size: 24px;
					color: #666666;

					.num {
						color: #1f4456;
					}
				}

				.btn {
					position: absolute;
					top: 0;
					right: 0;
					font-size: 24px;
					color: #1f4456;
					display: flex;
					align-items: center;
					
					img {
						width: 24px;
						height: 24px;
						margin-left: 8px;
						position: relative;
						top: 2px;
					}
				}
			}

			.tap-lnr {
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #1f4456;
				font-size: 24px;
				padding-top: 40px;
				margin-top: 24px;
				border-top: 1px solid #eee;
			}

		}
	}

	.add-btn {
		position: fixed;
		left: 50%;
		bottom: 0;
		z-index: 10000;
		transform: translateX(-50%);
		width: 100%;
		height: 114px;
		max-width: 750px !important;
		color: #fff;
		font-size: 28px;
		background-color: #fff;
		box-shadow: 0 2px 24px #eee;
		padding: 14px 30px;
		display: flex;
		justify-content: space-around;
		align-items: center;
		text-align: center;
		
		.btn {
			color: #999999;
			font-size: 24px;
			display: flex;
			flex-direction: column;
			justify-content: flex-start;
			align-items: center;
			max-width: 18%;
			margin: 0 12px;
			height: 100%;
			
			&.select {
				color: #1f4456;
			}
			
			img {
				width: 38px;
				height: 38px;
				margin-bottom: 8px;
				object-fit: contain;
			}
		}
	}

</style>